package com.syh.controller;

import com.syh.pojo.People;
import com.syh.service.PeopleService;
import com.syh.utils.Result;
import com.xxl.job.core.handler.annotation.XxlJob;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author syh
 * @date 2023/3/10-13:48
 */
@SuppressWarnings("all")
@RestController
@Api(value ="人员管理",tags = {"人员22管理接口"})
@RequestMapping("/people")
public class EmployeeController {
    @Autowired
    PeopleService peopleService;
    @PostMapping("/loginEmploy")
    @ApiOperation(value = "登录")
    public Result loginPeople(@RequestBody People employee){
        try {
            People user=peopleService.selectpeople(employee.getName());
            if (user.getGender().equals(employee.getGender())) {
                return Result.ok(user);
            }else {
                return Result.error("密码错误");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("新增失敗");
        }
    }
    @PostMapping("/insertEmploy")
    @ApiOperation(value = "新增人员")
    public Result insertPeople(@RequestBody People employee){
        try {
           peopleService.insertpeople(employee);
            return Result.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("新增失敗");
        }
    }
    @PostMapping("/updateEmploy")
    @ApiOperation(value = "修改人员")

    public Result updatePeople(@RequestBody People people){
        //分页查询商品列表
        try {
           peopleService.updatepeople(people);

            return Result.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("修改失敗");
        }
    }
    @GetMapping("/selectAllPeople")
    @ApiOperation(value = "查询全部人")
//    @XxlJob("demoJobHandler")
    public Result selectAllPeople(){
        //分页查询商品列表
        try {
            System.out.println("11111");
            List<People> i = peopleService.selectAll();
            return Result.ok(i);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查詢失敗");
        }
    }
}
